package cn.bopomo.dealer.uloo.service.impl;

import java.rmi.RemoteException;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.bopomo.dealer.base.util.Page;
import cn.bopomo.dealer.base.util.SecurityUtil;
import cn.bopomo.dealer.uloo.common.UlooConstant;

import com.vpn888.www.BpGuestbook;
import com.vpn888.www.BpVpnConsumeVO;
import com.vpn888.www.Page4WebService;
import com.vpn888.www.services.UlooBackStage.BackStageProxyProxy;

public class UlooBackStageServiceImpl{


	private Log log = LogFactory.getLog(getClass());
	
	public Page showGuestBookList(int curPage, int rowsPerPage, String startDate, String endDate) throws RemoteException{
		if(startDate==null ){
			startDate="";
		}
		if(endDate==null){
			endDate="";
		}
		//生成MD5验证字符
		String v_Md5Str = SecurityUtil.MD5(
							curPage +
							rowsPerPage +
							startDate +
							endDate +
							UlooConstant.MD5_KEY);
		
		BackStageProxyProxy proxy = new BackStageProxyProxy();
		Page4WebService page4WebService = proxy.showGuestBookList(curPage, rowsPerPage, startDate, endDate, v_Md5Str);
		if(page4WebService == null){
			log.warn("<<=====不能获取留言板列表!!"); 
			return null;
		}
		log.info("=====>获取留言板列表: " + page4WebService.getCurPage() + "/" + page4WebService.getMaxPage() + " 页    总记录数:" + page4WebService.getMaxRowCount()); 
		Page pageList = new Page();
		pageList.setList(page4WebService.getList());
		pageList.setCurPage(page4WebService.getCurPage());
		pageList.setMaxPage(page4WebService.getMaxPage());
		pageList.setRowsPerPage(page4WebService.getRowsPerPage());
		pageList.setMaxRowCount(page4WebService.getMaxRowCount());
		HashMap parameterMap = new HashMap();
		if(!(startDate.equals("")||startDate==null)){
			parameterMap.put("startDate", startDate);
		}
		if(!(endDate.equals("")||endDate==null)){
			parameterMap.put("endDate", endDate);
		}
		if(parameterMap.size()>0){
			pageList.setParameterMap(parameterMap);
		}else{
			parameterMap=null;
		}
		return pageList;
	}
	
	public BpGuestbook showGuestBookDetail(int id) throws RemoteException{
		if(id == 0 ){
			return null;
		}
		//生成MD5验证字符
		String v_Md5Str = SecurityUtil.MD5(
				id +
				UlooConstant.MD5_KEY);
		//获取代理
		BackStageProxyProxy proxy = new BackStageProxyProxy();
		BpGuestbook bpGuestbook = proxy.showGuestBookDetail(id,v_Md5Str);
		if(bpGuestbook == null){
			log.warn("<<=====不能获取Vpn消费详情!!"); 
			return null;
		}
//		BpGuestbook bpGuestbook = new BpGuestbook();
		log.warn("=====>>已获取留言  id:" + bpGuestbook.getId() + "  主题:" + bpGuestbook.getTitle());
		return bpGuestbook;
	}
	
	
	public Page showVpnConsumeList(int curPage, int rowsPerPage, String startDate, String endDate) throws RemoteException{
		if(startDate==null ){
			startDate="";
		}
		if(endDate==null){
			endDate="";
		}
		//生成MD5验证字符
		String v_Md5Str = SecurityUtil.MD5(
							curPage +
							rowsPerPage +
							startDate +
							endDate +
							UlooConstant.MD5_KEY);
		
		BackStageProxyProxy proxy = new BackStageProxyProxy();
		Page4WebService page4WebService = proxy.showVpnConsumeList(curPage, rowsPerPage, startDate, endDate, v_Md5Str);
		if(page4WebService == null){
			log.warn("<<=====不能获取Vpn消费列表!!"); 
			return null;
		}
		log.info("=====>获取Vpn消费列表: " + page4WebService.getCurPage() + "/" + page4WebService.getMaxPage() + " 页    总记录数:" + page4WebService.getMaxRowCount()); 
		Page pageList = new Page();
		pageList.setList(page4WebService.getList());
		pageList.setCurPage(page4WebService.getCurPage());
		pageList.setMaxPage(page4WebService.getMaxPage());
		pageList.setRowsPerPage(page4WebService.getRowsPerPage());
		pageList.setMaxRowCount(page4WebService.getMaxRowCount());
		HashMap parameterMap = new HashMap();
		if(!(startDate.equals("")||startDate==null)){
			parameterMap.put("startDate", startDate);
		}
		if(!(endDate.equals("")||endDate==null)){
			parameterMap.put("endDate", endDate);
		}
		if(parameterMap.size()>0){
			pageList.setParameterMap(parameterMap);
		}else{
			parameterMap=null;
		}
		return pageList;
	}
	
	
	
	
	public BpVpnConsumeVO showVpnConsumeDetail(int id) throws RemoteException{
		if(id == 0 ){
			return null;
		}
		//生成MD5验证字符
		String v_Md5Str = SecurityUtil.MD5(
				id +
				UlooConstant.MD5_KEY);
		//获取代理
		BackStageProxyProxy proxy = new BackStageProxyProxy();
		BpVpnConsumeVO bpVpnConsumeVO = proxy.showVpnConsumeDetail(id, v_Md5Str);
		if(bpVpnConsumeVO == null){
			log.warn("<<=====不能获取Vpn消费详情!!"); 
			return null;
		}
//		BpGuestbook bpGuestbook = new BpGuestbook();
		log.warn("=====>>已获取vpn消费详情  id:" + bpVpnConsumeVO.getId() );//+ "  主题:" + bpVpnConsumeVO.g);
		return bpVpnConsumeVO;
	}
	
	
	
	
}
